import { create, update, remove, query } from '../../../../../framework/service/index';

const proIcon = require('../../../../../icons/personal/default-avatar.jpg')
export default {

  namespace: 'myWallet',

  state: {
    date: [],
    selectedIndex: 0,
    billNavIndex: 0,
    myBalanceInfo:'',
    incomeDetailList:[],
    incomeDetailList:[],
  },

  subscriptions: {
    setup({ dispatch, history }) {
      history.listen(location => {
        if(location.pathname === '/my-wallet') {
          dispatch({
            type: 'getBalance',
          })
          dispatch({
            type: 'getIncomeDetail',
          })
        }
      })
    },
  },



  effects: {
    //获取账号余额
    *getBalance({ payload }, { call, put, select }) {
      const { code, data, message } = yield call(query, '/api/applicants/balance', {});
      if(code == 200){
        yield put({
          type: 'querySuccess',
          payload: {
            myBalanceInfo: data
          }
        })
      }
    },

    //收入明细
    *getIncomeDetail({ payload }, { call, put, select}) {

      const pageNum = 1;
      const pageSize = 10;

      const { code, data, message } = yield call(query, '/api/applicants/income', {
        pageNum,
        pageSize
      });

      // console.log('code', JSON.stringify(code));
      // console.log('data', JSON.stringify(data));
      // console.log('message', JSON.stringify(message));

      if(code == 200){
        yield put({
          type: 'querySuccess',
          payload: {
            incomeDetailList:data,
          }
        })
      }

    },

    //支出明细
    *getPayDetail({ payload }, { call, put, select}) {

      const pageNum = 1;
      const pageSize = 10;

      const { code, data, message } = yield call(query, '/api/applicants/expenditure', {
        pageNum,
        pageSize
      });

      // console.log('code', JSON.stringify(code));
      // console.log('data', JSON.stringify(data));
      // console.log('message', JSON.stringify(message));

      if(code == 200){
        yield put({
          type: 'querySuccess',
          payload: {
            payDetailList:data,
          }
        })
      }

    },

  },

  reducers: {
    querySuccess(state, action) {
      return { ...state, ...action.payload };
    },
  }

};
